package com.jiazhong.example.project.bookstore.commons.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiazhong.example.project.bookstore.commons.bean.Book;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

@Mapper
public interface BookMapper extends BaseMapper<Book> {
    @Select("select * from book b ,discount d where b.is_deleted=0 and b.id=d.book_id order by d.discount_rate limit #{number}")
    List<Book> findLower(int number);

    @Select("select * from book b ,discount d where b.is_deleted=0 and b.id=d.book_id order by d.discount_rate limit #{start},10")
    List<Book> findLowerMore(int start);

    @Select("select * from book b ,discount d where b.is_deleted=0 and b.id=d.book_id and b.name like #{bookname} order by d.discount_rate limit #{start},10")
    List<Book> findLowerAndBooknameMore(@Param("start") int start, @Param("bookname") String bookname);

    @Select("select count(0) from book b ,discount d where b.is_deleted=0 and b.id=d.book_id order by d.discount_rate")
    int findLowerMoreCount();

    @Select("select count(0) from book b ,discount d where b.is_deleted=0 and b.id=d.book_id and b.name like #{bookname} order by d.discount_rate")
    int findLowerAndBooknameMoreCount(String bookname);

    List<Book> findBookByBookId(Set<String> set);
}
